package com.gviiii.baiduai.config.impl;

import com.gviiii.baiduai.config.ConfigHandler;
import com.gviiii.baiduai.config.ConfigStrategy;
import com.gviiii.baiduai.util.PropertiesUtil;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;

public class ClasspathStrategy implements ConfigStrategy {

    @Override
    public Map<String,String> doOperation(String confFile) {
        try {
            return createConfigMap(confFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Collections.emptyMap();
    }

    private Map<String,String> createConfigMap(String confFile) throws IOException {
        Properties properties = PropertiesUtil.getProperties();
        properties.load(PropertiesUtil.loadPropertiesByClasspath(confFile));
        return ConfigHandler.initConfig(properties);
    }
}
